package com.zheng1.envii.room.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.zheng1.envii.room.entity.EnvIIBleDeviceDataEntity
import kotlinx.coroutines.flow.Flow


@Dao
interface EnvIIBleDeviceDataDao {

    @Insert( onConflict = OnConflictStrategy.IGNORE)
    suspend fun insertDeviceData(deviceData: EnvIIBleDeviceDataEntity)

    @Query("DELETE FROM envii_ble_device_data WHERE deviceAddress = :address")
    suspend fun deleteDeviceDataByAddress(address: String)

    @Query("SELECT * FROM envii_ble_device_data WHERE deviceAddress = :address  ORDER BY id DESC")
    fun getDeviceDataByAddress(address: String): Flow<List<EnvIIBleDeviceDataEntity>>
}